package cn.com.eado.crm.v.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

open class BaseFragment(private val layoutId: Int) : Fragment() {

    private var isViewInit = false//记录是否已经初始化过一次视图
    private var lastView: View? = null//记录上次创建的view

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (lastView == null) {
            lastView = View.inflate(container?.context, layoutId, null)
        }
        return lastView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        if (!isViewInit){
            super.onViewCreated(view, savedInstanceState)
            initTheFragment()
            isViewInit = true
        }
    }

    open fun initTheFragment(){}  //从另一个fragment返回本fragment时，该方法都会执行一次
}